package com.global.college.ui.presenter;

import android.content.Context;

import com.global.college.api.ProgressSubscriber;
import com.global.college.base.BasePresenter;
import com.global.college.ui.bean.GoodsDetailModel;
import com.global.college.ui.bean.OrderCreateModel;
import com.global.college.ui.bean.requestBean.CallBackModel;
import com.global.college.ui.interfaces.IPayView;

/**
 * 支付
 */
public class PayPresenter extends BasePresenter {

    private IPayView mIPayView;

    public PayPresenter(Context context) {
        super(context);
    }

    public void setPayView(IPayView payView){
        mIPayView = payView;
    }
    /**
     * 商品详情
     * @param
     */
    public void getGoodsDetail(String goodId){
        mRequestClient.getGoodsDetail(goodId).subscribe(new ProgressSubscriber<GoodsDetailModel>(mContext,true) {
            @Override
            public void onNext(GoodsDetailModel object) {
                if(null != mIPayView){
                    mIPayView.onGoodsDetailSuccess(object);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIPayView){
                    mIPayView.onGoodsDetailFail(e.getMessage());
                }
            }
        });
    }

    /**
     * 创建订单
     * @param
     */
    public void createOrder(String userId, String goodId){
        mRequestClient.createOrder( userId,  goodId).subscribe(new ProgressSubscriber<OrderCreateModel>(mContext,true) {
            @Override
            public void onNext(OrderCreateModel object) {
                if(null != mIPayView){
                    mIPayView.onCreateOrderSuccess(object);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIPayView){
                    mIPayView.onCreateOrderFail(e.getMessage());
                }
            }
        });
    }
    /**
     * 支付回调
     * @param
     */
    public void payCallBack(CallBackModel params){
        mRequestClient.payCallBack(params).subscribe(new ProgressSubscriber<Object>(mContext,true) {
            @Override
            public void onNext(Object object) {
                if(null != mIPayView){
                    mIPayView.onPayCallBackSuccess(object);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIPayView){
                    mIPayView.onPayCallBackFail(e.getMessage());
                }
            }
        });
    }



}
